{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 常量操作\n",
    "a = tf.constant(2)\n",
    "b = tf.constant(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a: 2\n",
      "b: 3\n",
      "Addition with constants: 5\n",
      "Multiplication with constants: 6\n"
     ]
    }
   ],
   "source": [
    "# 创建会话，并执行计算操作\n",
    "with tf.Session() as sess:\n",
    "    print(\"a: %i\" % sess.run(a))\n",
    "    print(\"b: %i\" % sess.run(b))\n",
    "    print(\"Addition with constants: %i\" % sess.run(a + b))\n",
    "    print(\"Multiplication with constants: %i\" % sess.run(a * b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 占位符操作\n",
    "# x = tf.placeholder(dtype, shape, name)\n",
    "x = tf.placeholder(tf.int16, shape=(), name=\"x\")\n",
    "y = tf.placeholder(tf.int16, shape=(), name=\"y\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算操作\n",
    "add = tf.add(x, y)\n",
    "mul = tf.multiply(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Addition with variables: 15\n",
      "Multiplication with variables: 6\n"
     ]
    }
   ],
   "source": [
    "# 加载默认数据流图\n",
    "with tf.Session() as sess:\n",
    "    # 不填充数据，直接执行操作，报错\n",
    "    print(\"Addition with variables: %i\" % sess.run(add, feed_dict={x: 10, y: 5}))\n",
    "    print(\"Multiplication with variables: %i\" % sess.run(mul, feed_dict={x: 2, y: 3}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载默认数据流图\n",
    "with tf.Session() as sess:\n",
    "    # 不填充数据，直接执行操作，报错\n",
    "    print(\"Addition with variables: %i\" % sess.run(add, feed_dict={x: 2, y: 3}))\n",
    "    print(\"Multiplication with variables: %i\" % sess.run(mul, feed_dict={x: 2, y: 3}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "venv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
